home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 3 code / ISO 9660 & High Sierra / iso9660 ƒ / support.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-15  |  9.4 KB  |  439 lines  |  [TEXT/KAHL]

  1. /************************************************************************
  2.  *
  3.  *    Copyright © 1990    Apple Computer, Inc.  All rights reserved.
  4.  *
  5.  ************************************************************************/
  6.  
  7. #include <MacTypes.h>
  8. #include <QuickDraw.h>
  9. #include <StdFilePkg.h>
  10. #include <HFS.h>
  11.  
  12. #include <stdio.h>
  13. #include <ctype.h>
  14. #include <string.h>
  15.  
  16. #include "support.h"
  17.  
  18. typedef    unsigned char    byte;
  19.  
  20.  
  21. /************************************************************************
  22.  *
  23.  *  Function:        pStrCopy
  24.  *
  25.  *  Purpose:        copy a pascal string from p1 to p2
  26.  *
  27.  *  Returns:        nothing
  28.  *
  29.  *  Side Effects:    p2 gets filled with contents of p1
  30.  *
  31.  *  Description:    simple loop, copying from p1 to p2 for length
  32.  *                    determined by first byte of p1.
  33.  *
  34.  ************************************************************************/
  35. void
  36. pStrCopy( p1, p2 )
  37. register StringPtr p1;
  38. register StringPtr p2;
  39. {
  40.     register int len;
  41.     
  42.     len = *p2++ = *p1++;
  43.     while (--len>=0)
  44.         *p2++=*p1++;
  45. }
  46.  
  47.  
  48. /************************************************************************
  49.  *
  50.  *  Function:        pStrLen
  51.  *
  52.  *  Purpose:        return length of pascal string
  53.  *
  54.  *  Returns:        short
  55.  *
  56.  *  Side Effects:    none
  57.  *
  58.  *  Description:    The first byte of a pascal string contains the
  59.  *                    length of the string.  Return that value.
  60.  *
  61.  ************************************************************************/
  62. short
  63. pStrLen(p)
  64. register StringPtr p;
  65. {
  66.     return (p[0]);
  67. }
  68.  
  69.  
  70. /************************************************************************
  71.  *
  72.  *  Function:        CreateISOName
  73.  *
  74.  *  Purpose:        Create ISO name from pstring.
  75.  *
  76.  *  Returns:        nothing
  77.  *
  78.  *  Side Effects:    dest is filled.
  79.  *
  80.  *  Description:    An ISO file name is 31 characters plus '.;1', all
  81.  *                    in uppercase.  Copy and convert file name, with
  82.  *                    any bogus characters converted to underscore '_'.
  83.  *                    If there was no period in the file name,
  84.  *                    add one.  Add ";1" to the end of the file name.
  85.  *
  86.  ************************************************************************/
  87. short
  88. CreateISOName(dest, src)
  89. char        *dest;
  90. StringPtr    src;
  91. {
  92.     short    i;
  93.     short    limit;
  94.     short    nameSize;
  95.     char    c;
  96.     Boolean    madeDot;
  97.         
  98.     limit = pStrLen(src);
  99.     
  100.     dest[0] = toupper(src[1]);
  101.     
  102.     if (dest[0] == '\000' || dest[0] == '\001')
  103.         return 1;    /* don't add version stuff to myself or parent */
  104.  
  105.     for (i = 1; i < limit; i++)
  106.         dest[i] = (isalnum(src[i+1])) ? toupper(src[i+1]) : '_';
  107.     
  108.  
  109.     madeDot = false;
  110.     for (i = limit; i > 0 && madeDot == false; i--)
  111.         if (dest[i] == '_')
  112.         {
  113.             dest[i] = '.';
  114.             madeDot = true;
  115.         }
  116.  
  117.     nameSize = limit;
  118.     
  119.     if (madeDot == false)        /* we don't have a period. Add one */
  120.         dest[nameSize++] = '.';
  121.     dest[nameSize++] = ';';
  122.     dest[nameSize++] = '1';        /* version number */
  123.  
  124.     return nameSize;
  125. }
  126.  
  127. /************************************************************************
  128.  *
  129.  *  Function:        HFSFile
  130.  *
  131.  *  Purpose:        get the name and vRefNum of an HFS File
  132.  *
  133.  *  Returns:        Boolean
  134.  *                        true    a file was selected
  135.  *                        false    no file. Please stop
  136.  *
  137.  *  Side Effects:    *fn and *vRefNum get filled in
  138.  *
  139.  *  Description:    Call SFGetFile to get the file to be operated upon.
  140.  *
  141.  ************************************************************************/
  142. Boolean
  143. HFSFile( fn, vRefNum )
  144. StringPtr    fn;
  145. short        *vRefNum;
  146. {
  147.     Point    SFGwhere;
  148.     SFReply    reply;
  149.     
  150.     SFGwhere.v = 90;
  151.     SFGwhere.h = 82;
  152.     SFGetFile(SFGwhere, (StringPtr)"\pChoose File to Add to ISO disk", 0L, -1, 0L, 0L, &reply );
  153.     if (reply.good) {
  154.         pStrCopy( reply.fName, fn );
  155.         *vRefNum = reply.vRefNum;
  156.         return(true);
  157.     }
  158.     else return(false);
  159. }
  160.  
  161.  
  162.  
  163. /************************************************************************
  164.  *
  165.  *  Function:        ClearOut
  166.  *
  167.  *  Purpose:        set memory to zeros
  168.  *
  169.  *  Returns:        nothing
  170.  *
  171.  *  Side Effects:    *buffer is zeroed out
  172.  *
  173.  *  Description:    zero out buffer for count bytes.
  174.  *
  175.  ************************************************************************/
  176. void
  177. ClearOut(buffer, count)
  178. Ptr        buffer;
  179. short    count;
  180. {
  181.     short    i;
  182.     
  183.     for (i = 0; i < count; i++)
  184.         buffer[i] = 0;
  185. }
  186.  
  187.  
  188. /************************************************************************
  189.  *
  190.  *  Function:        SpaceOut
  191.  *
  192.  *  Purpose:        set memory to spaces
  193.  *
  194.  *  Returns:        nothing
  195.  *
  196.  *  Side Effects:    *buffer is spaced out
  197.  *
  198.  *  Description:    Put spaces into buffer for count bytes.
  199.  *
  200.  ************************************************************************/
  201. void
  202. SpaceOut(buffer, count)
  203. Ptr        buffer;
  204. short    count;
  205. {
  206.     short    i;
  207.     
  208.     for (i = 0; i < count; i++)
  209.         buffer[i] = ' ';
  210. }
  211.  
  212.  
  213. /************************************************************************
  214.  *
  215.  *  Function:        CharCopy
  216.  *
  217.  *  Purpose:        copy and fill with blanks
  218.  *
  219.  *  Returns:        nothing
  220.  *
  221.  *  Side Effects:    *dest is filled with contents of src & blanks
  222.  *
  223.  *  Description:    copy from *src to *dest for the length specified.
  224.  *                    src is assumed to point to a C null-delimited string.
  225.  *                    If src is smaller than length in size, dest is filled
  226.  *                    with blanks.
  227.  *
  228.  ************************************************************************/
  229. void
  230. CharCopy(dest, src, length)
  231. char *dest;
  232. char *src;
  233. short length;
  234. {
  235.     short     i;
  236.     short    j;
  237.     
  238.     i = 0;
  239.     while (*dest++ = *src++)
  240.         i++;
  241.     
  242.     *dest--;
  243.     i--;    /* so that no null terminator is left over */
  244.     
  245.     if (i < length)
  246.         for (j = i; j < length; j++)
  247.             *dest++ = ' ';
  248. }
  249.  
  250.  
  251.  
  252.  
  253. /************************************************************************
  254.  *
  255.  *  Function:    NormalizeLong
  256.  *
  257.  *  Purpose:    normalize a long number that's in lsb format
  258.  *
  259.  *  Returns:    long
  260.  *
  261.  *  Side Effects:    none
  262.  *
  263.  *  Description:
  264.  *                takes a long in lsb format order and converts it
  265.  *                to msb format order.  For example, the long value
  266.  *                0x12345678 becomes 0x78563412
  267.  *                0x78563412 becomes 0x12345678
  268.  *
  269.  *
  270.  ************************************************************************/
  271. long
  272. NormalizeLong(incoming)
  273. long    incoming;
  274. {
  275.     byte    *byteArray;
  276.     long    result;
  277.     
  278.     byteArray = (byte *) &incoming;
  279.     result = (long) byteArray[0] | 
  280.              (long) byteArray[1] << 8 | 
  281.              (long) byteArray[2] << 16 |
  282.              (long) byteArray[3] << 24;
  283.     
  284.     return result;
  285. }
  286.  
  287. /************************************************************************
  288.  *
  289.  *  Function:    NormalizeWord
  290.  *
  291.  *  Purpose:    normalize a word number that's in lsb format
  292.  *
  293.  *  Returns:    word
  294.  *
  295.  *  Side Effects:    none
  296.  *
  297.  *  Description:
  298.  *                takes a word in lsb format order and converts it
  299.  *                to msb format order.  For example, the word value
  300.  *                0x1234 becomes 0x3412
  301.  *                0x3412 becomes 0x1234
  302.  *
  303.  *
  304.  ************************************************************************/
  305. short
  306. NormalizeWord(incoming)
  307. short    incoming;
  308. {
  309.     byte    *byteArray;
  310.     short    result;
  311.     
  312.     byteArray = (byte *) &incoming;
  313.     result = (short) byteArray[0] | 
  314.              (short) byteArray[1] << 8;
  315.     
  316.     return result;
  317. }
  318.  
  319.  
  320. /************************************************************************
  321.  *
  322.  *  Function:    NormalizeVolumeName
  323.  *
  324.  *  Purpose:    convert a string to conform to ISO 9660 naming standards
  325.  *
  326.  *  Returns:    none
  327.  *
  328.  *  Side Effects:    changes the string "someString"
  329.  *
  330.  *  Description:
  331.  *                ISO 9660 forces volume names to be only alphanumeric
  332.  *                characters plus underscore.  This routine converts a
  333.  *                string of arbitrary length to such a volume name string,
  334.  *                converting all illegal characters to underscore.
  335.  *
  336.  *
  337.  ************************************************************************/
  338. void
  339. NormalizeVolumeName(someString)
  340. char *someString;
  341. {
  342.     int    i;
  343.     
  344.     for (i = 0; i < strlen(someString); i++)
  345.         someString[i] = (isalnum(someString[i])) ? toupper(someString[i]) : '_';
  346. }
  347.  
  348.  
  349. /************************************************************************
  350.  *
  351.  *  Function:        GetFileInfo
  352.  *
  353.  *  Purpose:        get lengths of file rsrc and data forks
  354.  *
  355.  *  Returns:        OSErr
  356.  *                        noErr, unless PBHGetVInfo has an error.
  357.  *
  358.  *  Side Effects:    dataLength & rsrcLength are changed
  359.  *
  360.  *  Description:     call PBGetFInfo() and return its results.
  361.  *
  362.  ************************************************************************/
  363. OSErr
  364. GetFileInfo(name, vRefNum, rsrcLength, dataLength, fType, fCreator, flags)
  365. StringPtr    name;
  366. short        vRefNum;
  367. long        *rsrcLength;
  368. long        *dataLength;
  369. OSType        *fType;
  370. OSType        *fCreator;
  371. short        *flags;
  372. {
  373.     HParamBlockRec    io;
  374.     OSErr            result;
  375.     
  376.     io.fileParam.ioCompletion = 0L;
  377.     io.fileParam.ioNamePtr = name;
  378.     io.fileParam.ioVRefNum = vRefNum;
  379.     io.fileParam.ioFVersNum = 0;
  380.     io.fileParam.ioFDirIndex = 0;
  381.     result = PBGetFInfo((ParmBlkPtr)&io, false);
  382.     if (result == noErr)
  383.     {
  384.         *rsrcLength = io.fileParam.ioFlRLgLen;
  385.         *dataLength = io.fileParam.ioFlLgLen;
  386.         *fType = io.fileParam.ioFlFndrInfo.fdType;
  387.         *fCreator = io.fileParam.ioFlFndrInfo.fdCreator;
  388.         *flags = io.fileParam.ioFlFndrInfo.fdFlags;
  389.     }
  390.     else
  391.     {
  392.         *rsrcLength = 0L;
  393.         *dataLength = 0L;
  394.         *fType = 0L;
  395.         *fCreator = 0L;
  396.         *flags = 0;
  397.     }
  398.     return result;
  399. }
  400.  
  401.  
  402. /************************************************************************
  403.  *
  404.  *  Function:        GetFinderFlags
  405.  *
  406.  *  Purpose:        get finder flags for a file
  407.  *
  408.  *  Returns:        OSErr
  409.  *                        noErr, unless PBGetFInfo has an error.
  410.  *
  411.  *  Side Effects:    flags value is changed
  412.  *
  413.  *  Description:     call PBGetFInfo() and return its results.
  414.  *
  415.  ************************************************************************/
  416. OSErr
  417. GetFinderFlags(name, vRefNum, flags)
  418. StringPtr    name;
  419. short        vRefNum;
  420. short        *flags;
  421. {
  422.     HParamBlockRec    io;
  423.     OSErr            result;
  424.     
  425.     io.fileParam.ioCompletion = 0L;
  426.     io.fileParam.ioNamePtr = name;
  427.     io.fileParam.ioVRefNum = vRefNum;
  428.     io.fileParam.ioFVersNum = 0;
  429.     io.fileParam.ioFDirIndex = 0;
  430.     result = PBGetFInfo((ParmBlkPtr)&io, false);
  431.     if (result == noErr)
  432.         *flags = io.fileParam.ioFlFndrInfo.fdFlags;
  433.     else
  434.         *flags = 0;
  435.     return result;
  436. }
  437.  
  438.  
  439.